﻿using System;
using System.Drawing;
using System.Windows.Forms;
using DevExpress.XtraEditors.Controls;
using LIK.WakeOnLan.Network;

namespace LIK.WakeOnLan.Controls
{
    public partial class ClientEditControl : UserControl
    {
        internal Action<NetworkClient> EditAction { get; set; }

        internal Action<string> DeleteAction { get; set; }

        internal Action<string> SelectAction { get; set; }

        internal NetworkClient NetworkClient
        {
            get { return networkClient; }
            set
            {
                networkClient = value;
                buttonEditNetClient.Text = networkClient.ToString();
            }
        }

        private NetworkClient networkClient = new NetworkClient();

        public ClientEditControl()
        {
            InitializeComponent();
            new ButtonEditClickHelper(buttonEditNetClient).Click += ClientEditControl_Click;
        }

        void ClientEditControl_Click(object sender, ButtonPressedEventArgs e)
        {
            if (e == null)
            {
                this.SelectAction(this.NetworkClient.MacAddress);
            }
            else if (e.Button.Index == 0)
            {
                this.EditAction(this.networkClient);
            }
            else if (e.Button.Index == 1)
            {
                this.DeleteAction(this.networkClient.MacAddress);
            }
        }

        private void buttonEditNetClient_MouseHover(object sender, EventArgs e)
        {
            buttonEditNetClient.BackColor = Color.AliceBlue;
        }

        private void buttonEditNetClient_MouseLeave(object sender, EventArgs e)
        {
            buttonEditNetClient.BackColor = Color.White;
            buttonEditNetClient.Refresh();
        }


    }
}
